package com.yzd.learnjava.generics;

import java.util.Date;

public class Decoration {
	public static void main(String[] args) {
		TimeStamp timeStamp1 = new TimeStamp(new Basic2());
		TimeStamp timeStamp2 = new TimeStamp(new SerialNumber(new Basic2()));
		
		SerialNumber serialNumber1 = new SerialNumber(new Basic2());
		SerialNumber serialNumber2 = new SerialNumber(new TimeStamp(new Basic2()));
	}
}

class Basic2{
	private String value ;
	public void set(String val) {
		this.value = val;
	}
	
	public String get() {
		return value;
	}
}

class Decorator extends Basic2{
	protected Basic2 basic;
	public Decorator(Basic2 basic) {
		this.basic = basic;
	}
	
	public void set(String val) {
		basic.set(val);;
	}
	
	public String get() {
		return basic.get();
	}
}

class TimeStamp extends Decorator{
	private final long timeStamp ;
	
	public TimeStamp(Basic2 basic) {
		super(basic);
		timeStamp = new Date().getTime();
	}
	
	public long getStamp() {
		return timeStamp;
	}
}

class SerialNumber extends Decorator{
	private static long counter = 1 ;
	private final long serialNumber = counter++;
	
	public SerialNumber(Basic2 basic) {
		super(basic);
	}
	
	public long getSerialNumber() {
		return serialNumber;
	}
}
